package org.gordonframework.site.transitions {
	import org.gordonframework.core.events.GProcessEvent;
	import org.gordonframework.core.tween.GTween;
	import org.gordonframework.site.transitions.GTransition;	

	/**
	 * @author sampet
	 */
	public class GAlphaFade extends GTransition {

		private var inDuration:Number;
		private var outDuration:Number;

		public function GAlphaFade(inDuration:Number = 0.5, outDuration:Number = 0.5) {
			this.outDuration = outDuration;
			this.inDuration = inDuration;
		}

		override protected function hideView():void {
			if(currentView) {
				var tween:GTween = new GTween( currentView, {alpha:0}, outDuration * durationMultiplier, currentView.outro( durationMultiplier ), GTween.easeOut );
				tween.addEventListener( GProcessEvent.COMPLETE, tweenOutCompleteHandler );
				tween.start( );
			} else {
				hideViewComplete();
			}
		}

		private function tweenOutCompleteHandler(event:GProcessEvent):void {
			currentView.visible = false;
			hideViewComplete();
		}

		override protected function showView():void {
			currentView.visible = true;			currentView.alpha = 0;
			var tween:GTween = new GTween( currentView, {alpha:1}, inDuration * durationMultiplier, 0, GTween.easeIn );
			tween.addEventListener( GProcessEvent.COMPLETE, tweenInCompleteHandler );
			tween.start( );
		}

		private function tweenInCompleteHandler(event:GProcessEvent):void {
			currentView.intro( durationMultiplier );
			showViewComplete();
		}
	}
}
